<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>ViTools</title>
    <style>
      body {
        background-color: red;
      }
    </style>
  </head>
  <body>
    hello Vitools openFile
    <button onclick="handleClick()">配置</button>
    <button onclick="handleGetOsHomeDir()">get os home dir</button>
    <h2>
      utools的api
      <ul class="api_list"></ul>
    </h2>
  </body>
  <script>
    (function () {
      if (!window.isUTools) return;

      console.log(window.utoolsPreload.readFile());
      const api_list = document.querySelector('.api_list');
      for (let fnName of Object.keys(window.utools)) {
        if (window.utools.hasOwnProperty(fnName)) {
          const liDom = document.createElement('li');
          liDom.innerText = fnName;
          api_list.appendChild(liDom);
        }
      }
    })();

    utools.onPluginEnter(({ code, type, payload, optional }) => {
      console.log(
        'Debugger ~ utools.onPluginEnter ~ code,type,payload, optional:',
        code,
        type,
        payload,
        optional,
      );
    });
    
    function handleClick() {
      console.log('12323');
      window.history.replaceState({}, '', '/pages/setting.html');
    }
    function handleGetOsHomeDir() {
      console.log(window.utoolsPreload.getHomedir());
    }
  </script>
</html>
